swift get keys from dictionary

220

let dict: [Int: String] = [1: "one", 2: "two", 4: "four"]

if let key = dict.someKey(forValue: "two") { 
    print(key)
} // 2
componentArray = Array(dict.keys) // for Dictionary

componentArray = dict.allKeys // for NSDictionary

Comments

Submit
0 Comments